﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;

namespace QLGT_2
{
    public class kqtkGiaoTrinh
    {
        public string MaGiaoTrinh { get; set; }
        public string TenGiaoTrinh { get; set; }
        [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? HieuDinh { get; set; }
        public int MaNXB { get; set; }
        public string TenNXB { get; set; }
        public int GiaNiemYet { get; set; }
        public int MaTacGia { get; set; }
        public int MaHocHam { get; set; }
        public string HocHam { get; set; }
        public string VTHocHam { get; set; }
        public int MaHocVi { get; set; }
        public string HocVi { get; set; }
        public string VTHocVi { get; set; }
        public string TenTacGia { get; set; }
    }
    
    public class kqtkDaoTao
    {
        public string MaNganh { get; set; }
        public string TenNganh { get; set; }
        public int MaMonHoc { get; set; }
        public string TenMonHoc { get; set; }
        public string TenKhoa { get; set; }
        public string TenGiaoTrinh { get; set; }
        public int NamHoc { get; set; }
        public int KyHoc { get; set; }
        public int SoTinChi { get; set; }
    }

    public class kqthkGiaoTrinh
    {
        //[Display(Name = "Mã Giáo trình")]
        public string MaGiaoTrinh { get; set; }
        public string TenGiaoTrinh { get; set; }
        [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
        public DateTime? HieuDinh { get; set; }
        public int MaNXB { get; set; }
        public string TenNXB { get; set; }
        public string Nam { get; set; }
        public int GiaNiemYet { get; set; }
        public int SoTrang { get; set; }
        public int MaTacGia { get; set; }
        public int MaHocHam { get; set; }
        public string HocHam { get; set; }
        public string VTHocHam { get; set; }
        public int MaHocVi { get; set; }
        public string HocVi { get; set; }
        public string VTHocVi { get; set; }
        public string TenTacGia { get; set; }
        public int MaHeDaoTao { get; set; }
        public string TenHeDaoTao { get; set; }
    }

    public class kqthkBanDatTon
    {
        public string MaGiaoTrinh { get; set; }
        public string TenGiaoTrinh { get; set; }
        public int SoLuongBan { get; set; }
        public int SoLuongDat { get; set; }
        public int SoLuongTon { get; set; }
        public int Nam { get; set; }
    }

    public class DynamicData
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public int Total { get; set; }
    }

    public static class DateTimeJavaScript
    {
        private static readonly long DatetimeMinTimeTicks =
           (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks;

        public static long ToJavaScriptMilliseconds(this DateTime dt)
        {
            return (long)((dt.ToUniversalTime().Ticks - DatetimeMinTimeTicks) / 10000);
        }
    }

    public enum KhoaTaiKhoan
    {
        [Display(Name = "Mở")]
        Mo,
        [Display(Name = "Khóa")]
        Khoa
    }
    
    public enum TrangThai
    {
        [Display(Name = "Sử dụng")]
        SuDung,
        [Display(Name = "Không sử dụng")]
        KhongSuDung
    }

    public class DuLieuChung
    {
        public static string NonUnicode(string text)
        {
            string[] arr1 = new string[] { "á", "à", "ả", "ã", "ạ", "â", "ấ", "ầ", "ẩ", "ẫ", "ậ", "ă", "ắ", "ằ", "ẳ", "ẵ", "ặ",  
                "đ",  
                "é","è","ẻ","ẽ","ẹ","ê","ế","ề","ể","ễ","ệ",  
                "í","ì","ỉ","ĩ","ị",  
                "ó","ò","ỏ","õ","ọ","ô","ố","ồ","ổ","ỗ","ộ","ơ","ớ","ờ","ở","ỡ","ợ",  
                "ú","ù","ủ","ũ","ụ","ư","ứ","ừ","ử","ữ","ự",  
                "ý","ỳ","ỷ","ỹ","ỵ",};
            string[] arr2 = new string[] { "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a",  
                "d",  
                "e","e","e","e","e","e","e","e","e","e","e",  
                "i","i","i","i","i",  
                "o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o","o",  
                "u","u","u","u","u","u","u","u","u","u","u",  
                "y","y","y","y","y",};
            for (int i = 0; i < arr1.Length; i++)
            {
                text = text.Replace(arr1[i], arr2[i]);
                text = text.Replace(arr1[i].ToUpper(), arr2[i].ToUpper());
            }

            return Regex.Replace(text.ToLower().Replace(@"'", String.Empty), @"[^\w]+", "-").Replace("\"", "-").Replace(":", "-");
        }

        public static string MaHoaMD5(string str)
        {
            Byte[] dauvao = ASCIIEncoding.Default.GetBytes(str);
            using (MD5 md5 = new MD5CryptoServiceProvider())
            {
                var daura = md5.ComputeHash(dauvao);
                return BitConverter.ToString(daura).Replace("-", "").ToLower();
            }
        }
    }

    public class CheckRole
    {
        public static bool IsRole(string role, string[] roles)
        {
            if (roles == null || roles.Length == 0 || !roles.Contains(role))
                return false;
            return true;
        }
    }
}